import axios from "axios";
import { ElMessage } from "element-plus";
//创建axios实例
const request = axios.create({
    baseURL: import.meta.env.VITE_APP_BASE_URL,
    timeout: 5000,
});
//请求拦截器
request.interceptors.request.use((config)=>{

    return config
})
//响应拦截器
request.interceptors.response.use((response)=>{

    return response.data
},(error)=>{
    let message = '';
    const status = error.response.status
    switch (status) {
        case 401:
            message = '登录已过期'
            break
        case 403:
            message = '无权访问'
            break
        case 404:
            message = '地址不存在'
            break
        case 500:
            message = '服务器错误'
            break
    }
    ElMessage.error(message)
    return Promise.reject(error)
})
export default request